import socket

import signal

import jira

stop = False

# 自定义信号处理函数
def my_handler(signum, frame):
    global stop
    stop = True
    print("终止")

signal.signal(signal.SIGINT, my_handler) #读取Ctrl+c信号

# 创建套接字
server_socker = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

# 绑定IP和端口
server_socker.bind(("10.50.25.58", 8020))
server_socker.listen(128)

request = jira.openRequests()
request, _ =  jira.jiraLogin(request, "E00266", "qwertyuiop#3")

try:
    # 变为监听套接字
    while not stop:
        client_socket, client_addr = server_socker.accept()
        print(client_addr)

        client_socket.recv(1024)
        dashborad = jira.jiraDashboard(request)

        response_header = "HTTP/1.1 200 OK\r\n\r\n"
        response_body=dashborad
        response = response_header + response_body
        client_socket.send(response.encode('utf-8'))
        client_socket.close()
except Exception as e:
    print(e)
